<?php
namespace php\widgets\editorxml;
use yii\helpers\Html;
use Yii;

class WebHomeSliderWidget extends WebWidget{
	public function run(){

		$options = $this->options;
		$shtml = '<div class="home_banner commbanner WebHomeSliderWidget '.(isset($options['class']) ? $options['class'] : '').'" id="'.(isset($options['class_id']) ? $options['class_id'] : '').'" style="'.(isset($options['style']) ? $options['style'] : '').'">';
		$shtml .= '<div class="w1200">';
		$shtml .= '<div class="index-slide slide" id="slide" alt="star">';
		foreach ((array)$this->value['value']['content']['path'] as $key => $val) {
			$option = isset($this->value['value']['content']['options'][$key]) ? $this->value['value']['content']['options'][$key] : '';
			$link = !empty($this->value['value']['content']['links'][$key]) ? $this->value['value']['content']['links'][$key] : '#';
			$shtml .= '<div class="img">'.Html::a(Html::img( $val ), $link, ['target'=> !empty($link) ? '_blank' : null]). Html::tag('div', $option, ['class'=>'option']) .'</div>';
		}
		$shtml .= '<div class="slide-bt"></div>';
		$shtml .= '</div>';
		$shtml .= '<button onclick="left()">'.Yii::t('app', 'Prev').'</button>';
		$shtml .= '<button onclick="right()">'.Yii::t('app', 'Next').'</button>';
		$shtml .= '</div>';
		$shtml .= '</div>';
		$this->registerJs();

		return $shtml;
	}

	public function registerJs(){
		$js = '
		jQuery(".picScroll-left").slide({titCell:".hd ul",mainCell:".bd ul",autoPage:true,effect:"left",autoPlay:true,vis:3,trigger:"click"});
		';
		$theme = \Yii::$app->view->theme;
		// $this->view->registerJsFile($theme->getUrl('js/jquery.bxslider.js'), ['position'=>\yii\web\View::POS_END]);
		$this->view->registerJsFile($theme->getUrl('js/banner.js'), ['position'=>\yii\web\View::POS_END]);
		// $this->view->registerJs($js, \yii\web\View::POS_END);
	}
}